/*------------------------------------------------------
                hou_elearningGEN beta v1.0
Author: xtrung.net@gmail.com
Write On: 04/27/2008
Create On:4/13/2012 11:22:53 AM
------------------------------------------------------*/
using hou_elearning.DataAccess.Base;
using hou_elearning.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;

namespace hou_elearning.DataAccess
{    
    public class DonviquanlyDAL : SqlProvider<DonviquanlyEntity>
    {
        static DonviquanlyDAL()
        {
            InitReader();
        }
        protected static void InitReader()
        {
            getFromReader=delegate(SqlDataReader dr)
            {
                DonviquanlyEntity entity = new DonviquanlyEntity();
				entity.PK_iDonviquanlyID = Int64.Parse("0"+dr["PK_iDonviquanlyID"].ToString());
				entity.sTendonviquanly = dr["sTendonviquanly"].ToString();
				entity.sDiachi = dr["sDiachi"].ToString();
				entity.sSodienthoai = dr["sSodienthoai"].ToString();
				entity.FK_iThutruongID = Int64.Parse("0"+dr["FK_iThutruongID"].ToString());
				entity.sChucvuthutruong = dr["sChucvuthutruong"].ToString();
                entity.sLogo = dr["sLogo"].ToString();
                return entity;
            };
        }
        public static DonviquanlyEntity GetOne(Int64 PK_iDonviquanlyID)
        {
            string cmdName = "spDonviquanly_GetByPK";
            SqlParameter p = new SqlParameter("@PK_iDonviquanlyID", PK_iDonviquanlyID);
            DonviquanlyEntity entity = GetOne(cmdName, p);
            return entity;
        }
        public static List<DonviquanlyEntity> GetAll()
        {
            string cmdName = "spDonviquanly_Get";
            return GetList(cmdName);
        }
        public static List<DonviquanlyEntity> GetByFK_iThutruongID(Int64 FK_iThutruongID)
		{
			string cmdName = "spDonviquanly_GetByFK_FK_iThutruongID";
			SqlParameter p = new SqlParameter("@FK_iThutruongID",FK_iThutruongID);
			List<DonviquanlyEntity> list = GetList(cmdName, p);
			return list;
		}
        public static int Add(DonviquanlyEntity entity)
        {
            string cmdName = "spDonviquanly_Insert";
            return Run(cmdName,true,initParams(entity));

        }
        public static bool Edit(DonviquanlyEntity entity)
        {
            string cmdName = "spDonviquanly_Update";
            return Run(cmdName,false,initParams(entity))>0;
        }
        public static bool Remove(Int64 PK_iDonviquanlyID)
        {
            string cmdName = "spDonviquanly_Delete";
            SqlParameter p = new SqlParameter("@PK_iDonviquanlyID", PK_iDonviquanlyID);
            return Run(cmdName,false,p)>0;
        }
        #region private
        private static SqlParameter[] initParams(DonviquanlyEntity entity)
        {
            SqlParameter[] p = new SqlParameter[7];
			p[0] = new SqlParameter("@PK_iDonviquanlyID", entity.PK_iDonviquanlyID);
			p[1] = new SqlParameter("@sTendonviquanly", entity.sTendonviquanly);
			p[2] = new SqlParameter("@sDiachi", entity.sDiachi);
			p[3] = new SqlParameter("@sSodienthoai", entity.sSodienthoai);
			p[4] = new SqlParameter("@FK_iThutruongID", entity.FK_iThutruongID);
			p[5] = new SqlParameter("@sChucvuthutruong", entity.sChucvuthutruong);
            p[6] = new SqlParameter("@sLogo", entity.sLogo);
            return p;
        }
        #endregion
       
    }
}